/**
 * @author LKQ
 * @date 2021/12/31 11:35
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.canConstruct("aa", "aab"));
    }

    public boolean canConstruct(String ransomNote, String magazine) {
        int m = ransomNote.length(), n = magazine.length();
        if (m > n) {
            // magazine中都不重复且全部使用，但长度不够
            return false;
        }
        int[] ransom = new int[26];
        int[] mag = new int[26];
        for (int i = 0; i < m; i++) {
            ransom[ransomNote.charAt(i) - 'a']++;
        }
        for (int j = 0; j < n; j++) {
            mag[magazine.charAt(j) - 'a']++;
        }
        for (int i = 0; i < 26; i++) {
            if (ransom[i] > mag[i]) {
                return false;
            }
        }
        return true;
    }
}
